package com.zhida.smartcontrol.pagectrl.lampmanager.lampdetail.autotime;

import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;
import com.zhida.smartcontrol.pagectrl.devicedetail.autotime.AutoTimeBean;

import java.util.Arrays;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 13:07
 * description:
 */

public class LampAutoPresenter extends BasePresenterImpl<LampAutoContract.View> implements LampAutoContract.Presenter {

    @Override
    public void inidData(Bundle bundle) {
        if (null == bundle) {
            return;
        }
        List<String> tabs = Arrays.asList(new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"});
        mView.inflateTab(tabs, bundle.getString("id"));
    }

    @Override
    public void requestTime(String id, int weekId) {
        Params params = Params.newBuilder()
                .add("lampSwitchId", id)
                .add("weekday", weekId + "")
                .build();
        mKalleCenter.get(Api.FIND_WAY_DATA, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                List<AutoTimeBean> timeList = JSON.parseArray(result, AutoTimeBean.class);
                mView.showTimeList(timeList);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }

}
